#!/usr/bin/env python3
"""
验证脚本：确保模型存在且可以被正确加载
"""
import sys
import bentoml

def main():
    try:
        print("检查模型 'iris_clf:latest' 是否存在...")
        model = bentoml.models.get("iris_clf:latest")
        print(f"✓ 模型找到: {model}")
        print(f"  路径: {model.path}")
        print(f"  标签: {model.tag}")
        
        # 尝试加载模型
        print("\n尝试加载模型...")
        loaded_model = bentoml.sklearn.load_model("iris_clf:latest")
        print(f"✓ 模型加载成功: {type(loaded_model)}")
        
        # 测试预测
        import numpy as np
        test_data = np.array([[5.1, 3.5, 1.4, 0.2]])
        prediction = loaded_model.predict(test_data)
        print(f"✓ 测试预测成功: {prediction}")
        
        return 0
    except bentoml.exceptions.NotFound as e:
        print(f"✗ 错误: 模型不存在 - {e}")
        print("\n请先运行: python train_model.py")
        return 1
    except Exception as e:
        print(f"✗ 错误: {e}")
        import traceback
        traceback.print_exc()
        return 1

if __name__ == "__main__":
    sys.exit(main())
